* Variable creation - Post-training -------------------------------------------------
	
	* (2) Post training month indicators
	
		* (2.1): Individual months
		forvalues m = 1(1)12 {
			gen months_`m' = (month == `m')
		}
		
		* (2.2): Month blocks
		mat month_create = 1, 4 \ 5, 8 \ 9, 12 \ 1, 12 \ 1, 3
		
		forvalues i = 1(1)`= rowsof(month_create)' {
		
			* Month identifiers
			local a = month_create[`i',1]
			local b = month_create[`i',2]
			gen months_`a'_`b' = inrange(month, `a', `b')
		
			* Interaction identifiers

			* Months X treatment
			gen months_`a'_`b'_t 		= months_`a'_`b' * treatment
		
		}
		
	* (3) Days-off
	gen days_off_non_iod = days_off - days_iod
		
	
	* (4) Variables for TRR subsetting: Level 1 & 2 combined
	gen l12_trr_C = trr_nf_p2020_1or2_C
	gen l23_trr_C = trr_nf_p2020_2or3_C
		
		foreach var in ///
			trr_s_i trr_sa_injury trr_officer_i trr_s_h  trr_s_hos_i_ix {
				
			gen l12_`var'_C 		= lv1_`var'_C + lv2_`var'_C
			gen l12_`var'_S 		= l12_`var'_C / l12_trr_C
			replace l12_`var'_S		= 0 ///
									  if missing(l12_`var'_S) & l12_trr_C == 0
		}
	
	
* (5) Indexing -----------------------------------------------------------------

	gl pp 1_4 													
						
	foreach period in $pp {
	di "`period'"
	
		preserve

			* Restrict the data set to the given period
			gen months_all = 1
			keep if months_`period' == 1
			
				
				* (1) PRS Outcomes
				foreach v in $prs_items {
				z_cal prs_`v'		
				}
				
					* PRS score without arrests
					egen prs_score = rowmean(z_prs*)
					
					* PRS score with arrest
					z_cal arrest_non_con_cop
					egen prs_score_w_arrs = rowmean(z_prs* z_arrest_non_con_cop)
								   
				 foreach v in $prs_items{
				 rename z_prs_`v' z_prs_`v'_`period' 
				 }
		   
				* (7) Clean up
				keep employee_id year_month ///
					prs_score_`period' prs_score_w_arrs_`period' ///
					days_iod_score_`period' days_all_score_`period' ///
					cohort
			
			tempfile score_`period'
			save `score_`period''

		restore
	}
	

* (6) Merging back index data --------------------------------------------------

	foreach period in $pp {
	merge 1:1 employee_id year_month using `score_`period'', nogen
	}
	
	
* (7) Create index outcome -----------------------------------------------------
* For regression purpose

	* Index outcomes 
	gl period 1_4
	
	foreach outcome in ///
		prs_score_w_arrs ///
		ttt_score ///
		injury_score injury_h_score injury_h_score_S ///
		days_all_score days_iod_score ///
		z_prs_warrant z_prs_veh_rec z_prs_firearm z_prs_traf_stop z_prs_driv_stop z_prs_cont z_prs_anov ///
		z_prs_haz_cit z_prs_nonhaz_cit z_prs_curf_vio z_prs_cta z_prs_park_cit z_arrest_non_con_cop ///
		i_complaint_pri i_complaint_sec i_complaints {
			
			* Replace the values
			foreach cut in A  {													//
			gen `outcome'_cut_`cut'm = .
			foreach period in $period {
				replace `outcome'_cut_`cut'm 	= `outcome'_`period' if months_`period' == 1
			}
			}
			
		}
	